package com.nbgroup.web.role;

import com.nbgroup.entity.Role;
import com.nbgroup.entity.User;
import com.nbgroup.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.security.Principal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by 18545 on 2019/7/10.
 */
@Controller
@RequestMapping("/role")
public class RoleTurnController {
    @Autowired
    private RoleService roleService;

    @RequestMapping(value = "/toRolePage", method = RequestMethod.GET)
    public String rolePage(Map<String, Object> map, Integer page, Integer pageSize, Principal principal) throws Exception {
        Page<Role> role = roleService.findByPage( page, pageSize);
        for (Role r:role.getContent()) {
            int userSizeByRoleId = roleService.getUserSizeByRoleId(r.getId() + "");
            r.setSize(userSizeByRoleId+"");
        }
//        Map<String, Object> map2=new HashMap<>();
//        map2.put("content",content );
//        map2.put("totalElements", role.getTotalElements());
//        map2.put("totalPages", role.getTotalPages());
        map.put("datas",role);
        return "role/role_list";
    }
}
